package main

import (
	"fmt"
	"sync"
)

type cond struct {
	L  sync.Mutex
	mu sync.Mutex
	ch chan struct{}
}

func (c *cond) Wait() {
	c.mu.Lock()
	ch := c.ch
	c.mu.Unlock()
	<-ch
	c.L.Lock()
}

func (c *cond) Signal() {
	c.mu.Lock()
	defer c.mu.Unlock()
	select {
	case c.ch <- struct{}{}:
	default:
	}
}

func (c *cond) Broadcast() {
	c.mu.Lock()
	defer c.mu.Unlock()
	close(c.ch)
	c.ch = make(chan struct{})

}

func main() {
	var co cond
	var wg sync.WaitGroup

	wg.Add(2)

	go func() {
		defer wg.Done()
		co.L.Lock()
		co.Wait()
		fmt.Println("GO RUN 1")
		co.L.Unlock()
	}()

	go func() {
		defer wg.Done()
		co.L.Lock()
		co.Wait()
		fmt.Println("GO RUN 2")
		co.L.Unlock()
	}()

	
}
